package cloudInformation.controller;

import cloudInformation.customer.MinioService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * @program: Smart School
 * @ClassName TestDataController
 * @description: 测试控制器
 * @author: 陈智博
 * @create: 2025-04-30 14:12
 * @Version 1.0
 **/
@RestController
@RequestMapping("/file")
@Slf4j
public class TestDataController {

    @Autowired
    private MinioService minioService;

    @PostMapping("/upload")
    public String uploadFile(MultipartFile file)
    {
        try {
            String s = minioService.uploadFile(file);
            return s;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/download")
    public void downloadFile(@RequestParam("fileName") String fileName, HttpServletResponse response)
    {
        try {
            log.info("请求download");
            InputStream inputStream = minioService.downloadFile(fileName);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/fileUrl")
    public String GetFileUrl(@RequestParam("fileName") String fileName)
    {
        try {
            String fileUrl = minioService.getFileUrl(fileName);
            return fileUrl;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
